public class LC_27 {
    public int removeElement(int[] nums, int val) {
        if(nums.length == 0)return 0;
        int slow = 0;
        int fast = nums.length-1;
        while(slow < fast){
            while(slow < fast && nums[slow] != val){
                slow++;
            }
            while(slow < fast && nums[fast] == val){
                fast--;
            }
            if(slow >= fast) break;
            int tmp = nums[slow];
            nums[slow++] = nums[fast];
            nums[fast--] = tmp;
        }
        return nums[slow] == val? slow : slow+1;
    }
}
